package cn.zn.base.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.zn.base.common.utils.SignUtil;
import cn.zn.base.service.SignService;
import org.springframework.stereotype.Service;

@Service
public class SimpleSignServiceImpl implements SignService {

    @Override
    public String getApiUrl(String url, String userCode, String salt, String corpId) {
        String token = SignUtil.signToken(userCode, salt);
        if (StrUtil.containsAny(url, PARAM_CODE)) {
            url = url.replaceAll(PARAM_CODE, userCode);
        }
        if (StrUtil.containsAny(url, PARAM_PASWORD)) {
            url = url.replaceAll(PARAM_PASWORD, token);
        }
        if (StrUtil.containsAny(url, PARAM_TOKEN)) {
            url = url.replaceAll(PARAM_TOKEN, userCode + "_" + token);
        }
        return url;
    }

}
